package XBase;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

/**
 * This class demonstrates collection relevant queries.
 * It shows how to find and query specific documents.
 */
public class XMLDatabase {
	/*
	private Context context = null;
	private String databaseName = null;
	
	public void ACT001_loadDatabase(String databaseName, String dirPath) throws BaseXException {
		this.databaseName = databaseName;
		this.context = new Context();
		new CreateDB(databaseName, dirPath).execute(context);
	}
	
	public String ACT002_doQuery(String querySyntax) throws BaseXException {
		String queryResult = new XQuery(querySyntax).execute(this.context);
		return queryResult;
	}
	
	public String ACT002_doQuery() throws IOException
	{
		String querySyntax = "";
		String readLine = null;
		File f = new File(Constant.FILENAME_QUERY);
		BufferedReader bis = new BufferedReader(new FileReader(f));
		while((readLine = bis.readLine()) != null){
			querySyntax = querySyntax + readLine;
		}
		return this.ACT002_doQuery(querySyntax);
	}
	
	public void ACT003_closeDatabase() throws BaseXException{
		new DropDB(this.databaseName).execute(this.context);
		this.context.close();
	}
	
	public void ACT004_writeQResult(String fileName, String result) throws IOException {
		FileOutputStream fp = new FileOutputStream(new File(fileName));
		fp.write(result.getBytes());
		fp.close();
	}
	
    public static void main(final String[] args) throws IOException {
    	System.out.println("Start to load xml file to database");
    	XMLDatabase xmlD = new XMLDatabase();
    	xmlD.ACT001_loadDatabase(args[0], args[1]);
    	xmlD.ACT004_writeQResult(args[2], xmlD.ACT002_doQuery());
    	xmlD.ACT003_closeDatabase();
    }
    */
}